package com.allen.app.zdemo.mq;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
import java.util.Objects;
import lombok.Data;
import lombok.ToString;

/**
* Description:rabbitmq队列消息
* @author Limiaojun
* @date 2020/03/12
*/
@Data
@ToString
@ApiModel(description = "rabbitmq队列消息")
public class RabbitmqDatas {

    public RabbitmqDatas(){

    }

    public RabbitmqDatas(String exchangeName,String queueName,Object businessId){
        this.exchangeName = exchangeName;
        this.queueName = queueName;
        this.businessId = Convert.toStr(businessId,null);
    }

    public RabbitmqDatas(String exchangeName,String queueName,String context,Object businessId,Long delayTime){
        this.exchangeName = exchangeName;
        this.queueName = queueName;
        this.context = context;
        this.businessId = Convert.toStr(businessId,null);
        this.delayTime = delayTime;
    }

    public RabbitmqDatas(String exchangeName,String queueName,String context,String status,Object businessId){
        this.exchangeName = exchangeName;
        this.queueName = queueName;
        this.context = context;
        this.status = status;
        this.businessId = Convert.toStr(businessId,null);
    }

    @ApiModelProperty(notes = "自增id", dataType = "Integer")
    private Integer id;

    @ApiModelProperty(notes = "信道名", dataType = "String")
    private String exchangeName;

    @ApiModelProperty(notes = "队列名", dataType = "String")
    private String queueName;

    @ApiModelProperty(notes = "数据", dataType = "String")
    private String context;

    @ApiModelProperty(notes = "businessId", dataType = "String")
    private String businessId;

    @ApiModelProperty(notes = "状态: SUCCESS(成功),FAIL(失败)", dataType = "String")
    private String status;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(notes = "创建时间", dataType = "Date")
    private Date createTime;

    @ApiModelProperty(notes = "延迟时间(毫秒)", dataType = "Long")
    private Long delayTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(notes = "mq执行时间", dataType = "Date")
    private Date runTime;

    public Date getRunTime() {
        if(Objects.nonNull(delayTime)){
            return DateUtil.offsetMillisecond(DateUtil.date(), delayTime.intValue());
        }
        return null;
    }
}
